import Vue from 'vue'
import axios from 'axios'

// 创建http
const http = axios.create({
  timeout: 1000 * 30,
  withCredentials: true,
  headers: {
    'Content-Type': 'application/json; charset=utf-8'
  }
})

/**
 * 请求拦截
 */
http.interceptors.request.use(request => {
  // 请求头 带上token
  request.headers.token = Vue.cookie.get('token')
  return request
}, error => {
  return Promise.reject(error)
})

/**
 * 响应拦截
 */
http.interceptors.response.use(response => {
  // 401 token失败
  // if (response.data && response.data.code === 401) {
    
  // }
})

export default http
